function DOMUtils() {
};

DOMUtils.getEventCode = function(e) {
  var code = null;
  if (!e) {
    e = window.event;
  }
  if (e) {
    if (e.keyCode) {
      code = e.keyCode;
    } else if (e.which) {
      code = e.which;
    }
  }
  return code;
};

DOMUtils.removeChildElements = function(elem) {
  while (elem && elem.firstChild) {
    elem.removeChild(elem.firstChild);
  }
};

DOMUtils.removeTableRows = function(table, rowsToKeep) {
  while (table.rows.length > rowsToKeep) {
    table.deleteRow(table.rows.length - 1);
  }
};

DOMUtils.findPos = function(elem) {
  var curleft = 0, curtop = 0;
  if (elem.offsetParent) {
    curleft = elem.offsetLeft;
    curtop = elem.offsetTop;
    while ((elem = elem.offsetParent)) {
      curleft += elem.offsetLeft;
      curtop += elem.offsetTop;
    }
  }
  return [ curleft, curtop ];
};

DOMUtils.getEvent = function() {
  if (window.parent == window) {
    return window.event || arguments.callee.caller.arguments[0];
  } else {
    return window.parent.event || arguments.callee.caller.arguments[0];
  }
};

DOMUtils.xDocSize = function() {
  var b = document.body, e = document.documentElement;
  var esw = 0, eow = 0, bsw = 0, bow = 0, esh = 0, eoh = 0, bsh = 0, boh = 0;
  if (e) {
    esw = e.scrollWidth;
    eow = e.offsetWidth;
    esh = e.scrollHeight;
    eoh = e.offsetHeight;
  }
  if (b) {
    bsw = b.scrollWidth;
    bow = b.offsetWidth;
    bsh = b.scrollHeight;
    boh = b.offsetHeight;
  }
  return {
    w : Math.max(esw, eow, bsw, bow),
    h : Math.max(esh, eoh, bsh, boh)
  };
};
